package ru.spbau.bytecode.graph;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;

import org.junit.Test;

import ru.spbau.bytecode.graph.Vertex;

public class VertexTest {
	
	private final String vertexName = "name";
	private final Vertex v1 = new Vertex(vertexName);
	private final Point p = new Point(5, 5);
	
	@Test
	public void testGetName() {
		assertEquals(vertexName, v1.getName());
	}
	
	@Test
	public void testEquals() {
		Vertex v2 = new Vertex(vertexName);
		assertEquals(v1, v2);
	}
	
	@Test
	public void testNotEquals() {
		Vertex v2 = new Vertex("anotherName");
		assertFalse(v1.equals(v2));
	}
	
	@Test
	public void testToString() {
		assertEquals(vertexName, v1.toString());
	}
	
	@Test
	public void testHashCode() {
		assertEquals('v', new Vertex("v").hashCode());
	}
	
	@Test
	public void testGetLocation() {
		v1.setLocation(p);
		assertEquals(p.x, v1.getLocation().x);
		assertEquals(p.y, v1.getLocation().y);
	}
	
	@Test
	public void testMove() {
		v1.setBounds(new Rectangle(0, 0, 20, 20));
		v1.setLocation(new Point(5, 5));
		v1.setSize(new Dimension(0, 0));
		
		v1.move(15, 11);
		assertEquals(15, v1.getLocation().x);
		assertEquals(15, v1.getLocation().y);
		
		v1.move(-5, -2);
		assertEquals(10, v1.getLocation().x);
		assertEquals(13, v1.getLocation().y);
		
		v1.move(-6, -6);
		assertEquals(5, v1.getLocation().x);
		assertEquals(7, v1.getLocation().y);
	}
	
	@Test
	public void testIsCatched() {
		v1.setCatched(true);
		assertTrue(v1.isCatched());
	}
	
	@Test
	public void testPointInside() {
		v1.setSize(new Dimension(10, 10));
		v1.setLocation(new Point(0, 0));
		
		assertTrue(v1.pointInside(new Point(5, 5)));
		assertTrue(v1.pointInside(new Point(0, 10)));
		assertFalse(v1.pointInside(new Point(5, 12)));
		assertFalse(v1.pointInside(new Point(12, 5)));
	}
	
	@Test
	public void testInvert() {
		boolean expected = v1.isVisible();
		v1.invert();
		assertEquals(expected, !v1.isVisible());
	}
	
	@Test
	public void testGetSize() {
		v1.setSize(new Dimension(10, 20));
		assertEquals(10, v1.getSize().width);
		assertEquals(20, v1.getSize().height);
	}
}
